package com.enjoy.xbase.db.impi;

import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import com.enjoy.xbase.db.handle.IDelete;
import com.enjoy.xbase.db.tools.DBTools;

public class MDelete implements IDelete {
    private SQLiteDatabase db;
    private String tabName;

    public MDelete(SQLiteDatabase db) {
        this.db = db;
    }
    public MDelete(SQLiteDatabase db,String tabName) {
        this.db = db;
        this.tabName=tabName;
    }

    @Override
    public int dell(String selection, String... selectionArgs) {
        if (TextUtils.isEmpty(tabName)){
            throw new RuntimeException("tableName未设置");
        }
        return db.delete(tabName, selection, selectionArgs);
    }

    @Override
    public int dell(Object... datas) {
        int icount=0;
        for (Object data:datas) {
            icount+=dell(data.getClass(),"id=?",DBTools.getDataId(data));
        }
        return icount;
    }

    @Override
    public int dellAll() {
        if (TextUtils.isEmpty(tabName)){
            throw new RuntimeException("tableName未设置");
        }
        return db.delete(tabName, null, null);
    }
}
